<template>
  <div>
    <h1> Hello el1</h1>
    <h1>Hello {{info}}</h1>
  </div>
</template>

<script>
  export default {
    data(){
      return{
        info:1,
        usr: {username:'tom',password:'123456'},
        user: new FormData(),
      }
    },
    beforeRouteEnter: (to, from, next) => {
      console.log("进入路由之前");
      next(vm => {
        vm.login()
      });
    },
    beforeRouteLeave: (to, from, next) => {
      console.log("进入路由之后");
      next();
    },
    methods: {
      getData: function() {
        this.$http({
          method: 'post',
          url: 'http://localhost:1017/eat/login?username=tom&password=123456'
        }).then(response=>(this.info=response.data)).catch(err => {
          console.log(err)
        })
      },
      login: function(){
        this.user.append("username","123");
        this.user.append("password","123456");
        this.$http.post("login",this.user)
        .then(response=>(this.info=response.data))
      }
    }
  }
</script>
